// pages/businessdetails/businessdetails.js
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    businessId: '',
    businessInfo: '',
    imgUrl: [],
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动切换
    interval: 3000, //自动切换时间间隔
    duration: 1000, //滑动动画时长
    inputShowed: false,
    inputVal: "",
    markers: [],
    polyline: [],
    controls: [{
      id: 1,
      iconPath: '/resources/location.png',
      position: {
        left: 0,
        top: 300 - 50,
        width: 50,
        height: 50
      },
      clickable: true
    }]
  },
  regionchange(e) {
    console.log(e.type)
  },
  markertap(e) {
    console.log(e.markerId)
  },
  controltap(e) {
    console.log(e.controlId)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id);
    this.setData({
      businessId: options.id
    });
    this.getBusiness(options.id);

    var that = this;
    wx.getLocation({
      type: "wgs84",
      success: function (res) {
        console.log(res)
        var latitude = res.latitude;
        var longitude = res.longitude;

        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,

        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  goMap() {
    wx.navigateTo({
      url: '../../pages/map/map?lng=' + this.data.businessInfo.position[0] + '&lat=' + this.data.businessInfo.position[1]

    })
  },
  getBusiness(id) {
    var data = {
      id: id
    };
    var that = this;
    app.ajaxPost('product/getBusiness', data, function (res) {
      var article = res.data.contentHtml;
      WxParse.wxParse('article', 'html', article, that, 0);
      var markers = [{
        iconPath: '../../static/images/icon/xzz.png',
        id: 0,
        longitude: res.data.position[0],
        latitude: res.data.position[1],
        width: 40,
        height: 40
      }];
      var polyline = [{
        points: [{
          longitude: res.data.position[0],
          latitude: res.data.position[1],
        }, {
          longitude: res.data.position[0],
          latitude: res.data.position[1],
        }],
        color: '#FF0000DD',
        width: 2,
        dottedLine: true
      }]

      that.setData({
        businessInfo: res.data,
        markers: markers,
        polyline: polyline

      })
    })
  },
  calltell() {

    wx.makePhoneCall({
      phoneNumber: this.data.businessInfo.tell,
    })
  }
})